package com.mikey.unsafe;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author :Mikey
 * @description :
 * @create :2022-09-20 16:06:00
 */
//java.util.ConcurrentModificationException
public class UnsafeSet {
    public static void main(String[] args) {
        /**
         *1.Set<String> set = Collections.synchronizedSet(new HashSet<>());
         */
        //Set<String> set = new HashSet<>();
       // Set<String> set = Collections.synchronizedSet(new HashSet<>());
        Set<String> set = new CopyOnWriteArraySet();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                set.add(UUID.randomUUID().toString().substring(1, 5));
                System.out.println(set);
            },String.valueOf(i)).start();
        }
    }
}
